/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package granjaWSPackage;

import granjawspackage.GranjaWS;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

/**
 * REST Web Service
 *
 * @author jonathan
 */
@Path("granjawsport")
public class granjaWSPort {
    private GranjaWS port;

    @Context
    private UriInfo context;

    /** Creates a new instance of granjaWSPort */
    public granjaWSPort() {
        port = getPort();
    }

    /**
     * Invokes the SOAP method hello
     * @param name resource URI parameter
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("hello/")
    public String getHello(@QueryParam("name")
    String name) {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.hello(name);
                return "aca estoy!";
                //return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method listarClientes
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("listarclientes/")
    public String getListarClientes() {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.listarClientes();
                return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method listarPaises
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("listarpaises/")
    public String getListarPaises() {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.listarPaises();
                return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method productosCliente
     * @param user resource URI parameter
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("productoscliente/")
    public String getProductosCliente(@QueryParam("user")
    String user) {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.productosCliente(user);
                return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method listarProductos
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("listarproductos/")
    public String getListarProductos() {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.listarProductos();
                return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method TconsultarSaldo
     * @param user resource URI parameter
     * @return an instance of javax.xml.bind.JAXBElement<java.lang.Float>
     */
    @GET
    @Produces("application/xml")
    @Consumes("text/plain")
    @Path("tconsultarsaldo/")
    public JAXBElement<Float> getTconsultarSaldo(@QueryParam("user")
    String user) {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.Float result = port.tconsultarSaldo(user);
                return new JAXBElement<java.lang.Float>(new QName("http//lang.java/", "float"), java.lang.Float.class, result);
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method TdisminuirSaldo
     * @param user resource URI parameter
     * @param cantidad resource URI parameter
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("tdisminuirsaldo/")
    public String getTdisminuirSaldo(@QueryParam("user")
    String user, @QueryParam("cantidad")
                 @DefaultValue("0.0")
    float cantidad) {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.tdisminuirSaldo(user, cantidad);
                return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method TaumentarSaldo
     * @param user resource URI parameter
     * @param cantidad resource URI parameter
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("taumentarsaldo/")
    public String getTaumentarSaldo(@QueryParam("user")
    String user, @QueryParam("cantidad")
                 @DefaultValue("0.0")
    float cantidad) {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.taumentarSaldo(user, cantidad);
                return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     * Invokes the SOAP method TenviarItems
     * @param userOrigen resource URI parameter
     * @param userDestino resource URI parameter
     * @param producto resource URI parameter
     * @param cantidad resource URI parameter
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("text/plain")
    @Consumes("text/plain")
    @Path("tenviaritems/")
    public String getTenviarItems(@QueryParam("userOrigen")
    String userOrigen, @QueryParam("userDestino")
    String userDestino, @QueryParam("producto")
    String producto, @QueryParam("cantidad")
                     @DefaultValue("0")
    int cantidad) {
        try {
            // Call Web Service Operation
            if (port != null) {
                java.lang.String result = port.tenviarItems(userOrigen, userDestino, producto, cantidad);
                return result;
            }
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }

    /**
     *
     */
    private GranjaWS getPort() {
        try {
            // Call Web Service Operation
            granjawspackage.GranjaWS_Service service = new granjawspackage.GranjaWS_Service();
            granjawspackage.GranjaWS p = service.getGranjaWSPort();
            return p;
        } catch (Exception ex) {
            // TODO handle custom exceptions here
        }
        return null;
    }
}
